#include "cmd_ping_website.h"
#include "ui_cmd_ping_website.h"

#include<QProcess>
#include<QDebug>
#include<QStringList>
#include<QString>
#include<QByteArray>
#include<QFile>
#include<QKeyEvent>

cmd_ping_website::cmd_ping_website(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::cmd_ping_website)
{
    ui->setupUi(this);



}

cmd_ping_website::~cmd_ping_website()
{
    delete ui;
}

void cmd_ping_website::on_pushButton_clicked()
{

    //获取用户输入的网址
    QString * website = new QString;
    *website = ui->inputweb->text();

    qDebug()<<*website;

    //将用户输入的网址输进cmd
    QProcess *process = new QProcess;
    process->start("cmd.exe", QStringList() << "/c" << "ping" << *website);


    //获得cmd返回的值，并输出到文字框中
    if (!process->waitForFinished())
    {
        qDebug() << "Failed to ping!";
    }
    QByteArray results;
    results = process->readAllStandardOutput();

    QString msg;
    msg = QString::fromLocal8Bit(results);

    ui->outputping->append(msg);
    ui->outputping->update();





}

